// pages/buying/buying.js
Page({

  /**
   * 页面的初始数据
   */

    data: {
      indicatorDots: false,
      autoplay: true,
      interval: 5000,
      duration: 1000,
      imgUrls: [
        "/pages/images/haibao/kongqijinghuaqi-1.jpg",
        "/pages/images/haibao/kongqijinghuaqi-2.jpg",
        "/pages/images/haibao/kongqijinghuaqi-3.jpg"
      ],
      promotionGood: [{
        "id": "001",
        "nowPrice": "1299.00",
        "endTime": "12:00",
        "name": "空气净化器 除异味 除甲醛 空气伴侣 轻音设计",
        "address": "北京市 海淀区",
        "promise": ["七天无理由退货", "货到付款", "运费险"]
      }]
  },
  intocart() {
      console.log('加入购物车')
  },
  buy() {
      console.log('立即购买')
  },
  onLoad: function() {
    const promotionGoodName = "promotionGood[0].name"
    const promotionGoodPrice = "promotionGood[0].nowPrice"
    const eventChannel = this.getOpenerEventChannel();
    eventChannel.on('sendData', (data) => {
      let goodName = ""
      if(data.good.id === "001") {
        goodName = "bingxiang";
      }else if (data.good.id === "002") {
        goodName = "fengshan";
      }else{
        goodName = "kongqijinghuaqi";
      }
      const imgUrl = [];
      for (let i = 1; i <= 3; i++){
        imgUrl.push(`/pages/images/haibao/${goodName}-${i}.jpg`);
        console.log(imgUrl)
      }
      this.setData({
        [promotionGoodName]: data.good.name,
        [promotionGoodPrice]: data.good.nowPrice,
        imgUrls: imgUrl
      })
      console.log(this.imgUrls)
     })
    }
  })
